package cc.vv.btpartyjob.partymanager.activity

import android.text.TextUtils
import android.view.View
import android.view.WindowManager
import cc.vv.baselibrary.bean.base.BaseResponseObj
import cc.vv.baselibrary.util.LKToastUtil
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.btpartyjob.partymanager.R
import cc.vv.btpartyjob.partymanager.delegate.ManagerBaseBinder
import cc.vv.btpartyjob.partymanager.delegate.ProjectCancelActivityDelegate
import cc.vv.btpartyjob.partymanager.moudel.resp.ProjectDetailCancelApplyResponseObj
import cc.vv.btpartyjob.partymanager.server.PartyManagerServer
import cc.vv.mvp.activity.BaseActivityMVP
import cc.vv.mvp.binder.BaseDataBinder

/**
 * 取消申请
 * Created by Chen.qi on 2018/10/30.
 */
class ProjectCancelActivity : BaseActivityMVP<ProjectCancelActivityDelegate>() {

    /**
     * 详情id
     */
    private var projectDetailId: String? = null

    /**
     * 类型 0:取消  1：延期
     */
    private var type: String? = null


    override fun initData() {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)

        try {
            projectDetailId = intent.getStringExtra("projectDetailId")
            type = intent.getStringExtra("type")
        } catch (e: Exception) {

        }

        if ("3" == type) {
            //取消
            viewDelegate?.setTopBarTitle("取消申请")
            viewDelegate?.serReaStr("取消原因")
        } else if ("2" == type) {
            //延期
            viewDelegate?.setTopBarTitle("延期申请")
            viewDelegate?.serReaStr("延期原因")
        }


    }

    override fun bindEvenListener() {
        viewDelegate?.setTitleBackBtnOnClick(object : BaseTopBarView.EventInterface {
            //返回
            override fun leftOnClick() {
                finish()
            }

            override fun leftCloseClick() {}
            override fun rightOnClick() {
            }
        })
        viewDelegate?.setOnClickListener(View.OnClickListener {
            //取消申请
            val reason = viewDelegate?.getCancelContent()
            if (TextUtils.isEmpty(reason)) {
                LKToastUtil.showToastShort("请输入原因")
                return@OnClickListener
            }
            PartyManagerServer.projectDetailCancelApply(projectDetailId, reason, type)
        }, R.id.tv_acaA_cancelSubmit)


    }

    override fun getDelegateClass(): Class<ProjectCancelActivityDelegate> {
        return ProjectCancelActivityDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return ManagerBaseBinder()
    }

    override fun getData(obj: BaseResponseObj<*>?) {
        super.getData(obj)
        when (obj) {
            is ProjectDetailCancelApplyResponseObj -> {
                LKToastUtil.showToastShort("提交成功，等待管理员审核")
                setResult(101)
                finish()
            }
        }
    }
}